package item

import (
	//"fmt"
	"github.com/astaxie/beego/orm"
	//"gitee.com/yesy/mdzs.git/g"
	. "gitee.com/yesy/mdzs.git/models"
)

func OneByIdInDB(strRoleId int64) *Item {
	if 0 == strRoleId {
		return nil
	}

	o := Item{RoleId: strRoleId}
	err := orm.NewOrm().Read(&o, "RoleId")
	if err != nil {
		return nil
	}
	return &o
}


func IdsInDB(page int) []Item {

	if page >= 1 {
		page = page-1
	}
	pagesize := 10
	var items []Item
	Items().OrderBy("-record_time").Limit(pagesize, page*pagesize).All(&items)

	return items
}

func Save(this *Item) (int64, error) {
	
	num, err := orm.NewOrm().Insert(this)
	
	return num, err
}

func Del(c *Item) error {
	//num, err := orm.NewOrm().Delete(c)
	//if err != nil {
	//	return err
	//}

	return nil
}

func Update(this *Item) error {
	
	return nil
}

func Items() orm.QuerySeter {
	return orm.NewOrm().QueryTable(new(Item))
}
